import http from "../../utils/httpRequest"

let shopConfigTest = {
    name: "God店铺",
    status: 1,
    packingPrice: 1,
    sendingPrice: 1,
    sendingNeedPrice: 1000,
    startTime: "09:30",
    endTime: "22:00",
    relationPhones: "17058179046,17058179045",
    relationQQ: "2414402332",
    relationWeixin: "cyr2414402332",
    address: "四川农业大学2区好易购旁边",
    notice: "09:30-22:00为营业时间段!", // 店铺公告
    description: "God店铺~",
}

let shopListTest = [
    {
        id: 1,
        wxPayMchId: "1268456652", // 微信支付商家id和apiKey
        wxPayApiKey: "00000000000000000000000000000000",
        wxGzhAppId: "wx23af8wv5dsdie14d", // 微信公众号appId和appSecret
        wxGzhAppSecret: "fd8c1d5sd8w53fe9f2a58acff37cdcb18",
        wxMpAppId: "wx23af855558ds44d", // 微信小程序的appId和appSecret
        wxMpAppSecret: "fd8c1d6dssd3fe9f2a548acff37cdcb18",
        certPEMPublicKey: "-----BEGIN CERTIFICATE-----\nMIID5jCCAKoZIhvcNAQEL...-----END CERTIFICATE-----\n", // 微信商家tls证书公钥和私钥
        certPEMPrivateKey: "-----BEGIN PRIVATE KEY-----\nMIID5jCCAKoZIhvcNAQEL...-----END PRIVATE KEY-----\n",
        merchantName: "陈亚如",
        printerId: "xxx",
        ...shopConfigTest, // 店铺配置信息
        createTime: "2021-12-05 15:56:28",
    }
]

// 获取店铺配置信息
export function getShopConfig(params) {
    http({
        ...params,
        path: "/shop/config",
        testData: shopConfigTest,
    })
}

// 修改店铺配置信息
export function updateShopConfig(params) {
    http({
        ...params,
        method: "put",
        path: "/shop/config",
        testData: function () {
            shopConfigTest = params.data
            return true
        },
    })
}

export function getShopList(params) {
    http({
        ...params,
        path: "/system/shop/list",
        testData: JSON.parse(JSON.stringify(shopListTest))
    })
}

export function addShop(params) {
    http({
        ...params,
        method: "post",
        path: "/system/shop",
        testData: function () {
            params.data.id = Math.random()
            shopListTest.push(params.data)
            return true
        },
    })
}

export function updateShop(params) {
    http({
        ...params,
        method: "put",
        path: "/system/shop/" + params.data.id,
        testData: function () {
            for (let i = 0; i < shopListTest.length; i++) {
                if (shopListTest[i].id === params.data.id)
                    shopListTest[i] = params.data
            }
            return true
        },
    })
}
